luci-base: form.js: fix removing just created named GridSection
authorJo-Philipp Wich <[email protected]>
Fri, 22 Jul 2022 21:41:05 +0000 (23:41 +0200)
committerJo-Philipp Wich <[email protected]>
Fri, 22 Jul 2022 22:15:06 +0000 (00:15 +0200)
commit1e7d9e4461ac5965aedcc8ccf7e48627d07e46ac
tree4dbb27d77bc3910fc47580fc2fa85cefce292c9c
parentdf15ea39ff869dda75c692f86a2391241062d163
luci-base: form.js: fix removing just created named GridSection

Since the `handleModalSave()` handler of the GridSection class invokes
`handleModalCancel()` after saving the data but before removing the
`addedSection` property, the `handleModalCancel` handler incorrectly
removed the uci section that has just been created.

This bug didn't affect anonymous GridSections because after saving the
id of the created section changes, causing the remove command to fail,
but for named ones with stable section IDs, the bug manifested.

Solve the issue by passing a flag to `handleModalCancel()` indicating
whether the method was called from a safe operation and use it do
decide whether to delete the new staged uci section or not.

Fixes: #5760
Signed-off-by: Jo-Philipp Wich <[email protected]>
(cherry picked from commit 2771360108cb3e2011c7c9cb4921a9047ea70910)
modules/luci-base/htdocs/luci-static/resources/form.js